//
//  DiscoverCell.m
//  soccer
//
//  Created by Hauler Lord on 15/9/17.
//  Copyright (c) 2015年 上官千城. All rights reserved.
//

#import "ODiscoverCell.h"

@implementation ODiscoverCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
   self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        if ([reuseIdentifier isEqualToString: @"scrollCell"]) {
            
            [self createScroll];
            return self;
        }else if ([reuseIdentifier isEqualToString:@"buttonCell"]) {
        
            
            [self createButton];
            return self;
        } else if ([reuseIdentifier isEqualToString:@"discoverCell"]) {
        
        
            [self createNews];
            return self;
        }
        
    }
    

    return nil;
}


//资讯
-(void)createNews
{

    self.newsImageV = [[UIImageView alloc] initWithFrame:CGRectMake(20, 10, 100, 80)];
    self.newsImageV.backgroundColor = [UIColor whiteColor];
    self.newsImageV.image = [UIImage imageNamed:@"我的_12-03@2x.png"];
    [self.contentView addSubview:self.newsImageV];
    
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10 + self.newsImageV.frame.size.width + self.newsImageV.frame.origin.x, self.newsImageV.frame.origin.y, WIDTH - 50 - self.newsImageV.frame.size.width, 30)];
    self.titleLabel.backgroundColor = [UIColor clearColor];
    self.titleLabel.text = @"弗格森:没想到鲁尼肯能破纪录";
    self.titleLabel.textColor = [UIColor blackColor];
    self.titleLabel.numberOfLines = 0;
    self.titleLabel.font = [UIFont systemFontOfSize:19];
    [self.contentView addSubview:self.titleLabel];
    
    //自定义label高度
    CGFloat height= [self heightOfMe:self.titleLabel.text];
    CGRect frame = self.titleLabel.frame;
    frame.size.height = height;
    self.titleLabel.frame = frame;
    
    
    
    
    
    
    self.newsLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.titleLabel.frame.origin.x, self.titleLabel.frame.origin.y + self.titleLabel.frame.size.height + 5, self.titleLabel.frame.size.width, 30)];
    self.newsLabel.backgroundColor = [UIColor clearColor];
    self.newsLabel.text = @"弗格森从来没想过鲁尼肯能追平他阿弗拉或发哦发货";
    self.newsLabel.numberOfLines = 0;
    self.newsLabel.font = [UIFont systemFontOfSize:16];
    self.newsLabel.textColor = [UIColor lightGrayColor];
    [self.contentView addSubview:self.newsLabel];
    
    

}


//四个模块按钮
-(void)createButton
{
    for (int i = 0; i < 4; i++) {
        
        UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];
        myButton.backgroundColor = [UIColor whiteColor];
        myButton.frame = CGRectMake(i%2*((WIDTH - 25)/2+5) + 10, i/2*77.5 + 10, (WIDTH - 25)/2, 67.5);
        myButton.tag = 2000 + i;
        [myButton setImage:[UIImage imageNamed:@"我的_12-03@2x.png"] forState:UIControlStateNormal];

        [myButton addTarget:self action:@selector(myButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:myButton];
        
    }
    
}

//可能喜欢cell
-(void)createScroll
{
    
    self.interestScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 80)];
    self.interestScroll.backgroundColor = [UIColor whiteColor];
    self.interestScroll.showsHorizontalScrollIndicator = NO;
    [self.contentView addSubview:self.interestScroll];
    
    

}


-(void)myButtonAction:(UIButton *)btn
{
    if (btn.tag == 2000) {
       
        NSLog(@"111");
    } else if (btn.tag == 2001) {
    
        NSLog(@"222");
    
    } else if (btn.tag == 2002) {
        
        NSLog(@"333");

    } else if (btn.tag == 2003) {
        
        NSLog(@"444");

    }

}


-(void)setInterestImage:(NSMutableArray *)interestImage
{
    for (int i = 0; i < interestImage.count; i++) {
       
        
        UIImageView *interestIV = [[UIImageView alloc] initWithFrame:CGRectMake(10 + i * 50 + 10 * i, 5, 50, 50)];
        interestIV.backgroundColor = [UIColor clearColor];
        interestIV.tag = 100 + i;
        interestIV.image = [UIImage imageNamed:[interestImage objectAtIndex:i]];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
        [interestIV addGestureRecognizer:tap];
        interestIV.userInteractionEnabled = YES;
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(interestIV.frame.origin.x, interestIV.frame.size.height + interestIV.frame.origin.y + 3, interestIV.frame.size.width, self.interestScroll.frame.size.height - 3 - 5 - interestIV.frame.size.height)];
        label.text = @"哈哈";
        label.textAlignment = NSTextAlignmentCenter;
        label.font = [UIFont systemFontOfSize:13];
        label.backgroundColor = [UIColor clearColor];
      
        [self.interestScroll addSubview:interestIV];
        [self.interestScroll addSubview:label];
        self.interestScroll.contentSize = CGSizeMake(interestImage.count * 50 + 10 * (interestImage.count + 1), 10);
        
    }


}

//自定义高度方法
-(CGFloat)heightOfMe:(NSString *)text
{
    
    CGSize size = CGSizeMake(self.titleLabel.bounds.size.width, 10000);
    NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:19] forKey:NSFontAttributeName];
    CGRect frame = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];;
    
    return frame.size.height;
    
    
}

//interestScroll轻拍方法
-(void)tapAction:(UITapGestureRecognizer *)tap
{

    NSLog(@"点击图片编号 == %ld",tap.view.tag);



}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
